import xlsxwriter
from faker import Faker
from get_data import getFieldName
from get_data import getFieldData


class FakerData:
    def __init__(self):
        self.faker = Faker("zh_CN")
        self.f = xlsxwriter.Workbook("test_data.xlsx")
        self.sheet = self.f.add_worksheet("Sheet1")

    # def getData(self):
    #     data = []
    #     dataline = int(input("请输入需要的数据行数："))
    #     if dataline > 0:
    #         i = 1
    #         while(i <= dataline):
    #             person = dict(zip(getFieldName(), getFieldData()))
    #             data.append(person)
    #             i += 1
    #
    #     return data

    def saveToXlsx(self):
        r = 0
        c = 0
        for i in getFieldName():
            self.sheet.write(r, c, i)
            c += 1
        r += 1
        dataline = input("请输入需要的数据行数：")
        while True:
            if dataline.isdigit() and int(dataline) > 0:
                k = 1
                while k <= int(dataline):
                    c = 0
                    for j in getFieldData(r):
                        if j == "M":
                            j = "女"
                        elif j == "F":
                            j = "男"
                        self.sheet.write(r, c, j)
                        c += 1

                    # print(str(r) + "/" + dataline)
                    r += 1
                    k += 1

                self.f.close()
                break

            else:
                dataline = input("请重新输入：")


if __name__ == "__main__":
    fake = FakerData()
    fake.saveToXlsx()
